package com.fuqi.android.zhongcai.base.mvp.presenter;

import android.util.Log;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.fuqi.android.zhongcai.base.mvp.view.IRegisterView;
import com.fuqi.android.zhongcai.base.request.api.RegisterApi;
import com.fuqi.android.zhongcai.base.request.result.RegisterResult;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;

/**
 * Created by Lenovo on 2016/9/5.
 */
public class RegisterPresenterImpl implements RegisterPresenterInter {

    private IRegisterView registerView;

    public RegisterPresenterImpl(IRegisterView registerView) {
        this.registerView = registerView;
    }

    @Override
    public void registerDo(String phone, String password, String veryfyCode) {
        RequestManager.getInstance().call(new RegisterApi(new RegisterApi.RegisterParams(phone, password,veryfyCode), respLoginListener, errorLoginListener));

    }


    Response.Listener<RegisterResult> respLoginListener = new Response.Listener<RegisterResult>() {

        @Override
        public void onResponse(RegisterResult response) {

            if (HandleCode.requestSuccess()) {
                Log.i("juner", "juner respListener response.LoginResult(): ");
                registerView.registerSuccess(response);
            }
    }};


    Response.ErrorListener errorLoginListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            registerView.registerFailed();
            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


}
